import { observable, computed, action, autorun } from "mobx";
import { ApiOfDictionaryList } from '#/utils/coreApiDefine';

class Store {
  @observable BoolOptionDS = [
    { value: true, label: '是' },
    { value: false, label: '否' },
  ]

  @observable PhysicalConnTypeDS = [
    { value: 'SOCKET', label: 'socket' },
    { value: 'SOCKET2', label: 'socket2' },
    { value: 'SNMP', label: 'snmp' },
    { value: 'SERIAL', label: '串口' },
    { value: 'OPC', label: 'opc' },
    { value: 'NETTY', label: 'netty' },
    { value: 'PLUGIN', label: '自定义' }
  ]

  @observable ResourceWorkModeDS = [
    { value: 'PULL', label: '拉取' },
    { value: 'PUSH', label: '推送' }
  ]

  @observable MetricValueTypeDS = [
    { value: 'NONE', label: '无' },
    {
      label: 'modbus',
      children: [
        { value: 'BYTE', label: 'byte' },
        { value: 'SHORT', label: 'short' },
        { value: 'USHORT', label: 'unsigned short' },
        { value: 'SHORT_SWAPPED', label: 'short swapped' },
        { value: 'USHORT_SWAPPED', label: 'unsigned short swapped' },
        { value: 'INT', label: 'int' },
        { value: 'UINT', label: 'unsigned int' },
        { value: 'INT_SWAPPED', label: 'int swapped' },
        { value: 'UINT_SWAPPED', label: 'unsigned int swapped' },
        { value: 'INT_SWAPPED_SWAPPED', label: 'int swapped swapped' },
        { value: 'UINT_SWAPPED_SWAPPED', label: 'unsigned int swapped swapped' },
        { value: 'LONG', label: 'long' },
        { value: 'ULONG', label: 'unsigned long' },
        { value: 'LONG_SWAPPED', label: 'long swapped' },
        { value: 'ULONG_SWAPPED', label: 'unsigned long swapped' },
        { value: 'FLOAT', label: 'float' },
        { value: 'FLOAT_SWAPPED', label: 'float swapped' },
        { value: 'DOUBLE', label: 'double' },
        { value: 'DOUBLE_SWAPPED', label: 'double swapped' },
      ]
    },
    {
      label: 'snmp',
      children: [
        { value: 'NUMBER', label: 'number' },
        { value: 'NUMBER_ARRAY', label: 'number array' },
        { value: 'STRING', label: 'string' },
      ]
    },
    {
      label: '通用',
      children: [
        { value: 'BINARY', label: 'binary' },
      ]
    },
  ]

  @observable ProtocolDS = [
    { value: 'OPC', label: 'opc' },
    { value: 'MODBUS_RTU', label: 'modbus rtu' },
    { value: 'MODBUS_TCP', label: 'modbus tcp' },
    { value: 'MODBUS_ASCII', label: 'modbus ascii' },
    { value: 'SNMP', label: 'snmp' },
    { value: 'PLUGIN', label: '自定义' },
  ]

  @observable MetricUsageTypeDS = [
    { value: 'COLLECT', label: '采集' },
    { value: 'CONTROL', label: '控制' },
  ]

  @observable PolicyTypeDS = [
    { value: 'POLICY_ALARM', label: '策略告警' },
    { value: 'GATEWAY_DISCONNECT', label: '通讯中断告警' },
    { value: 'DEVICE_FAULT', label: '设备故障告警' },
    { value: 'SYSTEM', label: '系统告警' },
    { value: 'POLICY_COMPLEX', label: '复杂策略告警' },
    { value: 'SUB_SYSTEM_ALARM', label: '子系统告警' },
  ]
  @observable PolicyExpTypeDS = [
    { value: 'COMPARE', label: '指标比较' },
    { value: 'CHANGE', label: '指标变化' },
    { value: 'PERCENTAGECHANGE', label: '指标变化率' },
    { value: 'SCOPECHANGE', label: '指标变化大小' },
    { value: 'CUSTOMIZE', label: '自定义' },
    { value: 'COMPLEX', label: '复杂告警' },
  ]
  @observable SnmpVersionDS = [
    { value: '0', label: 'v1' },
    { value: '1', label: 'v2c' },
    { value: '3', label: 'v3' },
  ]
  @observable PolicyExpSignDS = [
    { value: '>', label: '>' },
    { value: '>=', label: '>=' },
    { value: '<', label: '<' },
    { value: '<=', label: '<=' },
    { value: '==', label: '=' },
    { value: '!=', label: '!=' },
  ]
  @observable ResourceTypeDS = [];
  @observable MetricUnitDS = [];
  @observable PolicyEventStatusDS = [
    { value: 'FIXED', label: '解除' },
    { value: 'UNFIXED', label: '告警' },
  ];
  @observable SnmpAuthProtocolDS = [
    { value: 'md5', label: 'md5' },
    { value: 'sha', label: 'sha' },
    { value: 'sha224', label: 'sha224' },
    { value: 'sha256', label: 'sha256' },
    { value: 'sha384', label: 'sha384' },
    { value: 'sha512', label: 'sha512' }
  ]
  @observable SnmpPrivProtocolDS = [
    { value: 'des', label: 'des' },
    { value: 'aes128', label: 'aes128' },
    { value: 'aes192', label: 'aes192' },
    { value: 'aes256', label: 'aes256' }
  ]
  @observable MetricValueCategoryDS = [
    { value: 'DIGITAL', label: '数字量' },
    { value: 'ANALOG', label: '模拟量' },
    { value: 'OTHER', label: '其它' }
  ]
  @action fetchResourceTypes() {
    ApiOfDictionaryList('resource').then(
      action("fetchSuccess", data => {
        this.ResourceTypeDS = data.data.map(function (item) {
          return { value: item.code, label: item.text };
        });
      }),
      action("fetchError", error => {
      })
    )
  }
  @action fetchMetricUnits() {
    ApiOfDictionaryList('unit').then(
      action("fetchSuccess", data => {
        this.MetricUnitDS = data.data.map(function (item) {
          return { value: item.code, label: item.text };
        });
      }),
      action("fetchError", error => {
      })
    )
  }
}
const store = new Store();
autorun(() => store.fetchResourceTypes());
autorun(() => store.fetchMetricUnits());
export default store;
